var turntable_obj={
	turntable_init:function(){
		$('#startbtn').rotate({
			bind:{
				click:function(){
					var action = $('input[name=action]').val();
					$.post(action, 'TId='+tid, function(data){
						if(data.status==1){
							$('#startbtn').rotate({
								duration:6000,
								angle: data.rand, 
								animateTo:5400+data.rand,
								easing: $.easing.easeOutSine,
								callback: function(){
									if(data.prize){
										global_obj.win_alert(data.msg+'SN码为：'+data.sn, function(){
											$('#WinPrize').slideDown(500);
											$('#PrizeClass').html(data.prizemsg);
											$('#SnNumber').html(data.sn);
											$('#GetPrize input[name=MobilePhone]').focus();
										});	
										$('input[name=logid]').val(data.log);
										$('input[name=data]').val(data.data);
									}else{
										global_obj.win_alert(data.msg);
									}
								}
							});
						}else if(data.status==2){
							global_obj.win_alert(data.msg);
						}else if(data.errno == 1){
							global_obj.win_alert(data.msg);
							window.location = data.jumpurl;
							return ;
						}else if(data.status==3){
							global_obj.win_alert(data.msg);
						}else{
							global_obj.win_alert(data.msg);
							return false;
						}
					}, 'json');
				}
			}
		});
		
		var Phone=$('input[name=MobilePhone]');
		$('#GetPrize').submit(function(){return false;});
		$('#GetPrize input:submit').click(function(){
			if(Phone.val()==''){
				global_obj.win_alert('请填写手机号码！', function(){Phone.focus()});
				return false;
			}
			if(!(/^13\d{9}$/g.test(Phone.val()) || /^14[57]\d{8}$/g.test(Phone.val()) || /^15[0-35-9]\d{8}$/g.test(Phone.val()) || /^18\d{9}$/g.test(Phone.val()))){
				global_obj.win_alert("'"+Phone.val()+"'不是一个有效的手机号码！", function(){Phone.focus()});
				return false;
			}
			
			$(this).attr('disabled', true).val('提交中...');
			var saveurl = $('input[name=do_action]').val();
			$.post(saveurl, $('#GetPrize').serialize()+'&q=1', function(data){
				if(data.status==1){
					global_obj.win_alert('提交成功！', function(){
						window.top.location.reload();
					});
					/*$('input, select, textarea').attr('disabled', true);
					$('#turntable_success').show().animate({
						bottom:150,
						opacity:'0.7'
					}, 1500).animate({
						opacity:0
					}, 4000);
					$('#WinPrize').hide();
					$('#PrizeTips').show();
					window.top.location.reload();*/
				}else if(data.status==2 || data.status==3){
					global_obj.win_alert(data.msg, function(){
						$('#WinPrize').slideUp(200);
					});
//					window.location.reload();
				};
				$('#GetPrize input:submit').attr('disabled', false).val('提交');
			}, 'json');
		});
		
		
		$('#PrizeTips .prize_list li span a[href=#usesn]').click(function(){
			var sn=$(this).parent().attr('sn');
			$('#UsedSn').slideDown(200);
			$('#UsedSn #UsedSnNumber').text(sn);
			$('#UsedSn form input[name=sn]').val(sn);
			$('#UsedPrize input[name=bp]').focus();
			return false;
		});
		
		$('#UsedPrize').submit(function(){return false;});
		$('#UsedPrize input:submit').click(function(){
			if($('#UsedPrize input[name=bp]').val()==''){
				global_obj.win_alert('请输入商家密码！', function(){$('#UsedPrize input[name=bp]').focus()});
				return false;
			}
			
			$(this).attr('disabled', true).val('提交中...');
			$.post('?', $('#UsedPrize').serialize()+'&p=1', function(data){
				if(data.status==1){
					global_obj.win_alert('兑奖成功！', function(){window.top.location.reload();});
				}else{
					global_obj.win_alert(data.msg);
				};
				$('#UsedSn').slideUp(200);
				$('#UsedPrize input[name=bp]').val('');
				$('#UsedPrize input:submit').attr('disabled', false).val('提交');
			}, 'json');
		});
		
		$('#UsedPrize .close').click(function(){
			$('#UsedSn').slideUp(200);
		});
	}
}